package com.smartisee.springcloud.service;

import com.smartisee.springcloud.entities.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @Auther: sp
 * @Date: 2019/2/21 13:44
 * @Description:
 */

@Component //不要忘记添加，否则不好使
public class DeptClientServiceFallbackFactory implements FallbackFactory<DeptClientService> {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public Dept get(@PathVariable("id") long id) {
                return new Dept().setDeptno(id).setDname("该ID：" + id + "没有对应的信息，Consumer客户端提供降级服务信息，此刻服务provider已经关闭")
                        .setDb_source("no this database in MySQL");
            }

            @Override
            public List<Dept> list() {
                return null;
            }

            @Override
            public boolean add(@RequestBody Dept dept) {
                return false;
            }

            @Override
            public Object discovery() {
                return null;
            }
        };
    }
}
